package model;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

/**
 * LevelPack stores a list of filenames to be used to load levels.
 * LevelPack also stores the index of the currently selected level.
 * 
 * @author Alexander Craig
 */
public class LevelPack {
	/** stores the list of level file names */
	private ArrayList<String> levels;
	/** stores the index of the currently selected level, (or -1 if no levels are loaded) */
	private int curLevel;

	/**
	 * Generates a new, empty level pack.
	 */
	public LevelPack() {
		levels = new ArrayList<String>();
		curLevel = -1;
	}
	
	/**
	 * Adds the passed filename to the end of the level pack
	 * @param filename	the filename of the level to add
	 */
	public void addLevel(String filename) {
		levels.add(filename);
	}
	
	/**
	 * @return the filename of the next level to be loaded, or null if no more levels exit
	 */
	public String getNextLevel() {
		if(curLevel + 1 < levels.size()) {
			curLevel++;
			return levels.get(curLevel);
		}
		return null;
	}
	
	/**
	 * @return true if the current level is the last level
	 */
	public boolean isLastLevel() {
		return curLevel + 1 >= levels.size();
	}
	
	/**
	 * @return	the number of levels in the level pack
	 */
	public int numLevels() {
		return levels.size();
	}
	
	/**
	 * @param index	the index of the desired level file name
	 * @return	the filename, or null if an invalid index is specified
	 */
	public String get(int index) {
		if (index >= 0 && index < levels.size()) {
			return levels.get(index);
		}
		return null;
	}
	
	/**
	 * Resets the current level status (ie. getNextLevel will return the first level)
	 */
	public void resetCurLevel() {
		curLevel = -1;
	}
	
	/**
	 * Removes all entries from the LevelPack
	 */
	public void clear() {
		levels.clear();
		curLevel = -1;
	}	
}